# 描述: MCP测试工具
# 作者: 王茂林
# 时间: 2025/5/13 10:31
import asyncio

from mcp import ClientSession
from mcp.client.sse import sse_client


async def main():
    # 连接到SSE服务器
    async with sse_client(url="http://localhost:8182/sse") as streams:
        async with ClientSession(*streams) as session:
            # 初始化会话
            await session.initialize()

            # 列出可用工具
            tools_response = await session.list_tools()
            print('可用工具列表：')
            for tool in tools_response.tools:
                print(f" - {tool.name}: {tool.description}")

            # 调用工具
            print("\n调用工具")
            call_tool = await session.call_tool("get_user_info", {"auth_token": "53ae4cf2-4348-4d1c-a169-8fbfb0ecff79"})
            print(call_tool.content[0].text)


if __name__ == "__main__":
    asyncio.run(main())
